var jQ = jQuery.noConflict();
jQ(function(){
	jQ("#divpersonal_fun div.my_clips_menu a.clipindex").addClass("clipindexonit");
	var html="";
	for(var i=2020;i>=1950;i--){
		html+="<option value='"+i+"'>"+i+"</option>";
	}
	jQ("#mouth_fun_view_year").empty().append(html);
	window.scrollTo(0,0);
	jQ("#mainshareview").data("contacttype",1);
	getTodayDateInfo();
	analyzeUrl();
	initContactGroups();
	jQ("span.share-title input[name=shareraido]").click(function(){
		var val=eval(jQ(this).val());
		if(val){
			jQ("#share-contactchoose").fadeIn();
		}else{
			jQ("#share-contactchoose").fadeOut();
		}
	});
	jQ("#updateshares").mouseover(function(){
		jQ(this).css({"background-color": "#f8e9ca" });
	});
	jQ("#updateshares").mouseout(function(){
		jQ(this).css({"background-color": "#F9DEB6" });
	});
});


function initContactGroups(){
	jQ.ajax({
		type:"POST",
		url: "contactAjax!getExistGroupAndContacts.action",
		success:function(data){
			if(data!=null){
				jQ("#mainshareview").data("contactgroups",data);
				
			}
		}
	});
	
}


function showQuickContactGroup(id,name,membercount){
	var flag=false;
	if(jQ("#contactgrouplist").css("display")=="none"){
		flag=true;
	}
	var canbeadd=true;
	jQ("li",jQ("#contactgrouplist")).each(function(){
		var groupid=eval(jQ(this).attr("groupid"));
		if(groupid==eval(id)){
			canbeadd=false;
			return false;
		}
	});
	if(!canbeadd)
		return;
	var countstr;
	if(membercount>99){
		countstr=membercount+"+";
	}else{
		countstr=membercount;
	}
	var html="<li groupid='"+id+"'>";
	html+="<span class=\"groupicon\"></span>";
	html+="<span class=\"groupname\">"+name+"</span>";
	html+="<span class=\"groupcount\">["+countstr+"]</span>";
	html+="<a onclick='deleteContactGroup(this);'></a></li>";
	jQ("#contactgrouplist").append(html);
	if(jQ("#contactgrouplist").css("display")=="none"){
		jQ("#contactgrouplist").show();
	}
}

function deleteContactGroup(obj){
	var groupid=jQ(obj).parent().attr("groupid");
	var li=jQ("#contactgroup li[groupid="+groupid+"]");
	li.find("input:checkbox").attr("checked",false);
	jQ(obj).parent().remove();
	if(jQ("li",jQ("#contactgrouplist")).length==0){
		jQ("#contactgrouplist").hide();
	}
}

var shareloadlength=20;
function listenScroll() {
	if(jQ("tr.lastline").length>0){
		var bot = 50;
		if ((bot + jQ(window).scrollTop()) >= (jQ(document).height() - jQ(window).height())) {
			jQ(window.document).unbind("scroll",listenScroll);
			addLoadingLine();
			setTimeout(continueLoadDaysShare,2000);
		}
	}
}

function addLoadingLine(){
	jQ("tr.lastline").after(jQ("#loadingtr").clone());
}
function removeLoadingLine(){
	jQ("tr.lastline").nextAll().remove();
}
function getTodayDateInfo(){
	jQ.ajax({
		type: "POST",
		url:"calendarAjax!getDateInfo.action",
		success:function(data){
			if(data!=null&&data.length>0){
				var dataObj=eval("("+data+")");
				var year=dataObj.year;
				var month=dataObj.month;
				var day=dataObj.dayofmonth;
				jQ("#divtodaydetailtime").data("year",year);
				jQ("#divtodaydetailtime").data("month",month);
				jQ("#divtodaydetailtime").data("date",day);
				
				var weeknum=dataObj.weeknum;
				
				
				var date=new Date(year, month, day);
				var week=date.getDay();
				var weekStr=day_of_week2cn(week);
				var lunarmonth=dataObj.lunarmonth;
				var lunarday=dataObj.lunarday;
				var lunarholidayday=dataObj.lunarholidayday;
				
				var html="";
				
				html+="<span class='mtime'>今天</span><span>";
				html+=weekStr;
				html+="，";
				html+=year;
				html+="年";
				html+=(month+1);
				html+="月";
				html+=day;
				html+="日，第";
				html+=weeknum;
				html+="周，农历";
				html+=lunarmonth;
				html+="";
				html+=lunarday;
				html+=""
				if(lunarholidayday!=""){
					html+="，"+lunarholidayday+"";
				}
				html+="</span>";
				jQ("#divtodaydetailtime").empty().append(html);
				
			}
		}
	});
}

function analyzeUrl(){
	var year=eval(getParameter("year"));
	var month=eval(getParameter("month"));
	var day=eval(getParameter("day"));
	var type=getParameter("type");
	var sloadtype=0;

	jQ("#mainshareview").data("contacttype",0);
	jQ("#sharetitle").empty().append("分享广场").removeClass().addClass("shareall");;
	jQ("#shareallplace").fadeOut();
	var usertype=eval(jQ("#var_usertype").val());
	if(usertype==1){
		jQ("#sharefriendplace").fadeIn();
	}
	type=0;
	sloadtype=1;
	if(!isNaN(year)&&year!=null
			&&!isNaN(month)&&month!=null
			&&!isNaN(day)&&day!=null
	){
		getShareEventsByMonth(year,month,day,eval(type));
	}else{
		getShareEventsByMonth(0,0,0,type);
	}
	sloadAllDetailShareevent(sloadtype);
}
/**
 * contacttype:	0 全部
 * 				1 好友
 * **/
function getShareEventsByMonth(yearNum,monthNum,day,contacttype){
	var temptype=contacttype;
	var vardate=day;
	jQ.ajax({
		type: "POST",
		url:"calendarAjax!getShareEventsByMonth.action",
		data:{
			year:eval(yearNum),
			month:eval(monthNum),
			contacttype:contacttype
		},
		success:function(data){
			jQ("tr.monthcontent td").attr("dayindex","");
			var year_month=jQ(data).find("year_month").attr("value");
			var year=eval(year_month.split("_")[0]);
			var month=eval(year_month.split("_")[1]);
			jQ("#calendarzonetitle").empty().append(year+"年"+(month+1)+"月");
			jQ("#calendar_monthcontrolbar").data("currentyear",year);
			jQ("#calendar_monthcontrolbar").data("currentmonth",month);
			jQ("#mouth_fun_view_year option[value='"+year+"']").attr("selected",true);
			jQ("#mouth_fun_view_month option[value='"+(month)+"']").attr("selected",true);
			var firstDateOfMonth=new Date(year,month,1);
			var week2=firstDateOfMonth.getDay();
			var week1=0;
			var startdate=new Date(year,month,1);
			if(week2>week1){
				startdate.setDate(firstDateOfMonth.getDate() -week2);
			}
			
			var endyear,endmonth;
			if(month==11){
				endmonth=0;
				endyear=year+1;
			}else{
				endmonth=month+1;
				endyear=year;
			}
			
			var endDateOfMonth=new Date(endyear,endmonth,1);
			endDateOfMonth.setDate(endDateOfMonth.getDate() -1);
			var week6=6;
			var week5=endDateOfMonth.getDay();
			
			
			var enddate=new Date(endyear,endmonth,1);
			enddate.setDate(enddate.getDate() -1);
			if(week5<week6){
				enddate.setDate(endDateOfMonth.getDate()+ (week6-week5));
			}
			var index=0;
			var tY=eval(jQ("#divtodaydetailtime").data("year"));
			var tM=eval(jQ("#divtodaydetailtime").data("month"));
			var tD=eval(jQ("#divtodaydetailtime").data("date"));
			jQ("#detailsharetimetable tr td").attr("index","");
			while(startdate.getTime()<=enddate.getTime()){
				var monthdayObj=jQ("#tdmonth"+index);
				jQ("#tdmonth"+index+" div.eventsign").hide();
				monthdayObj.attr("title",startdate.pattern("yyyy年MM月dd日"));
				var key="month"+startdate.pattern("MMdd");
				monthdayObj.removeClass().attr("classmodel","");
				//monthdayObj.addClass("month"+index);
				monthdayObj.data("date",startdate.getTime());
				var obj=jQ(data).find(key);
				var isThisMonth=eval(obj.find("isThisMonth").text());
				var startsharesize=eval(obj.find("startsharesize").text());
				var endsharesize=eval(obj.find("endsharesize").text());
				
				
				var isholiday=eval(obj.attr("holiday"));
				var weeknum=eval(obj.find("weeknum").text());
				var weekofmonth=eval(obj.find("weekofmonth").text());
				var weekday=eval(obj.find("weekday").text());
				var lunartxt=obj.find("lunartxt").text();
				/*if(isThisMonth){
					monthdayObj.addClass("normal").addClass("canquick");
				}else{
					monthdayObj.addClass("othermonth").addClass("canquick");
				}*/
				jQ("#tddetail"+index).removeClass();
				
				if(!isThisMonth){
					monthdayObj.addClass("other").attr("classmodel","other");
					jQ("#tddetail"+index).addClass("other");
				}else{
					monthdayObj.attr("dayindex",startdate.getDate());
					if(startdate.getDate()==1){
						monthdayObj.addClass("firstdayofmonth");
					}
				}
				if(isholiday){
					monthdayObj.addClass("holiday");
				}
				if(startsharesize>0){
					jQ("#tdmonth"+index+" div.starteventsign").show();
				}else{
					jQ("#tdmonth"+index+" div.starteventsign").hide();
				}
				if(endsharesize>0){
					jQ("#tdmonth"+index+" div.endeventsign").show();
				}else{
					jQ("#tdmonth"+index+" div.endeventsign").hide();
				}
				jQ("#tdmonth"+index+" div.sun").empty().append(startdate.getDate());
				//小小日历
				jQ("#tddetail"+index).empty().append(startdate.getDate());
				jQ("#tddetail"+index).attr("index",index);
				jQ("#tddetail"+index).attr("day",formateSmallDetailTime(startdate));
				
				
				jQ("#tdmonth"+index+" div.lunar").empty().append(lunartxt);
				var year=startdate.getFullYear();
				if(year==tY && startdate.getMonth()==tM && startdate.getDate()==tD){
					monthdayObj.addClass("today").attr("classmodel","today");
				}
				index++;
				startdate.setDate(startdate.getDate() +1);
			}
			jQ("#detailsharetimetable").data("index",index);
			if(index==28){
				jQ("#monthlast1").hide();
				jQ("#monthlast2").hide();
				jQ("tr[line=4]").hide();
			}else if(index==35){
				jQ("#monthlast1").show();
				jQ("#monthlast2").hide();
				jQ("tr[line=4]").show();
				jQ("tr[line=5]").hide();
			}else{
				jQ("#monthlast1").show();
				jQ("#monthlast2").show();
				jQ("tr[line=4]").show();
				jQ("tr[line=5]").show();
			}
			if(jQ("tr.monthcontent td.today").length>0&&vardate==0){
				var datetime=eval(jQ("td.today").data("date"));
				var temp=new Date();
				temp.setTime(datetime);
				var year=temp.getFullYear();
				var month=temp.getMonth();
				var date=temp.getDate();
				jQ("td.today").addClass(jQ("td.today").attr("classmodel")+"clickon");
				loadDetailShareevent(year,month,date);
			}else{
				var year=eval(jQ("#calendar_monthcontrolbar").data("currentyear"));
				var month=eval(jQ("#calendar_monthcontrolbar").data("currentmonth"));
				var date=0;
				var selectedobj=jQ("td[class!=other][dayindex="+vardate+"]");
				if(selectedobj.length>0){
					date=vardate;
				}
				if(date==0){
					var tmpmonthdayObj=jQ("td.firstdayofmonth");
					tmpmonthdayObj.addClass(tmpmonthdayObj.attr("classmodel")+"clickon");
					date=1;
				}else{
					selectedobj.addClass(selectedobj.attr("classmodel")+"clickon");
				}
					
				loadDetailShareevent(year,month,date);
			}
			jQ("#mouth_fun_prevyear").unbind( "click" );
			jQ("#mouth_fun_prevmonth").unbind( "click" );
			jQ("#mouth_fun_nextyear").unbind( "click" );
			jQ("#mouth_fun_nextmonth").unbind( "click" );
			jQ("#mouth_fun_prevyear").one("click",prevYearClick);
			jQ("#mouth_fun_prevmonth").one("click",prevMonthClick);
			jQ("#mouth_fun_nextyear").one("click",nextYearClick);
			jQ("#mouth_fun_nextmonth").one("click",nextMonthClick);
			jQ("#loadingui").hide();
			jQ("tr.monthcontent td").unbind("click").bind("click",function(){
				if(jQ(this).hasClass("clickon")||jQ(this).hasClass("todayclickon")||jQ(this).hasClass("otherclickon")){
					return;
				}else{
					jQ("#loadingui").show();
					jQ("tr.monthcontent td[class$=clickon]").removeClass("clickon").removeClass("todayclickon").removeClass("otherclickon");
					
					var classname=jQ(this).attr("classmodel");
					jQ(this).addClass(classname+"clickon");
					var datetime=eval(jQ(this).data("date"));
					var temp=new Date();
					temp.setTime(datetime);
					var year=temp.getFullYear();
					var month=temp.getMonth();
					var date=temp.getDate();
					loadDetailShareevent(year,month,date);
				}
			});
		}
	});
}
var circleCountFun=null;
function loadDetailShareevent(year,month,date){
	jQ(window.document).unbind("scroll",listenScroll);
	jQ("#smallcalendar").data("date",date);
	jQ("#smallcalendar").data("month",month);
	jQ("#smallcalendar").data("year",year);
	var tmp=year;
	jQ.ajax({
		type: "POST",
		url:"shareAjax!getShareEventsByDay.action",
		data:{
			year:year,
			month:month,
			date:date,
			contacttype:eval(jQ("#mainshareview").data("contacttype"))
		},
		success:function(data){
			jQ("#todayshare").empty().append(jQ(data).find("firstday").text());
			jQ("#crtclip").nextAll().remove();
			organizeShareEventsData(data);
			setTimeout(function(){
				jQ("#loadingui").hide();
			},1000);
		}
	});
}

function continueLoadDaysShare(){
	jQ(window.document).unbind("scroll",listenScroll);
	var date=eval(jQ("#smallcalendar").data("date"));
	var month=eval(jQ("#smallcalendar").data("month"));
	var year=eval(jQ("#smallcalendar").data("year"));
	// contacttype 应有记录读取
	jQ.ajax({
		type: "POST",
		url:"shareAjax!getShareEventsByDay.action",
		data:{
			year:year,
			month:month,
			date:date,
			contacttype:eval(jQ("#mainshareview").data("contacttype")),
			needmore:1
		},
		success:function(data){
			organizeShareEventsData(data);
		}
	});
}

function organizeShareEventsData(data){
	clearInterval(circleCountFun);
	circleCountFun=setInterval(loadNewShareRecords,30000);
	var length=jQ(data).find("ShareEvent").length;
	if(length==0){
		removeLoadingLine();
		if(jQ("#crtclip").nextAll().length==0){
			
			var emptyhtml="";
			for(var i=0;i<5;i++){
				emptyhtml+="<tr class='noline'><td>";
				emptyhtml+="<div class='simple'>";
				if(i==0){
					emptyhtml+="<span class=\"emptytxt\">暂无内容</span>";
				}
				emptyhtml+="</div>";
				emptyhtml+="</td></tr>";
			}
			
			jQ("#crtclip").after(emptyhtml);
		}
		return;
	}else{
		jQ("#crtclip").nextAll("tr.noline").remove();
		removeLoadingLine();
		jQ("tr.lastline").removeClass("lastline");
	}
	var htmljoin="";
	jQ(data).find("ShareEvent").each(function(i){
		var obj=jQ(this);
		var processstatus=eval(jQ(obj).find("processstatus").text());//
		var id=eval(jQ(obj).attr("id"));//
		var uid=jQ(obj).find("unameid").text();//
		var userlogo=jQ(obj).find("unamelogo").text();
		var title=jQ(obj).find("title").text();//
		var starttime=eval(jQ(obj).find("starttime").text());//
		var eventtype=jQ(obj).find("eventtype").text();//
		var hasaccept=eval(jQ(obj).find("isaccept").text());//
		var uname=jQ(obj).find("uname").text();
		var reliedclip=eval(jQ(obj).find("reliedclip").text());
		var timesituation=eval(jQ(obj).find("timesituation").text());
		var clipusertype=eval(jQ(obj).find("clipusertype").text());
		if(i==length-1)
			htmljoin+= "<tr class='lastline'>";
		else
			htmljoin+="<tr>";
		htmljoin+="<td id='clipevent-"+id+"' class='hasevent'  >";
		if(hasaccept)
			htmljoin+="<div class='simple' style='background:#fde9eb;'>";
		else
			htmljoin+="<div class='simple'>";
		
		htmljoin+="<span class='head' style=\"background:url('"+userlogo+"');\"><a href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+uid+"'></a></span>";
		htmljoin+="<span class='name'>";
		var length=getWordsLength(uname,12);
		if(length>100){
			htmljoin+="<a href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+uid+"' class='maxname' title='"+uname+"'>"+uname+"</a>";
		}else{
			htmljoin+="<a href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+uid+"' title='"+uname+"'>"+uname+"</a>";
		}
		if(clipusertype==2){
			htmljoin+="<span class='v_icon' title='档期认证'></span>";
		}
		htmljoin+="</span>";
		htmljoin+="<span class=\"title\">"+title+"</span>";
		if(timesituation==1){
			htmljoin+="<span class='icon' title='结束于今日' style=\"background:url('"+jQ("#ctxVal").val()+"/image/cal_opt_shareclip.png') -16px 0\"></span>";
		}else if(timesituation==-1){
			htmljoin+="<span class='icon' title='开始于今日' style=\"background:url('"+jQ("#ctxVal").val()+"/image/cal_opt_shareclip.png')\"></span>";
		}
		htmljoin+="<span class=\"ocopen\"></span>";
		htmljoin+="<span class=\"time\">"+formateDetailTimeWithhourmin(starttime)+"</span>";
		htmljoin+="</div>";
		htmljoin+="<div class='detail'>";
		htmljoin+="</div>";
		htmljoin+="</td>";
		
		htmljoin+="<div class='ptitle' onclick='myfunc(this)'><div class='"+eventtype+"'></div>"+title+"</div>";
		htmljoin+="</div></td></tr>";
		
	});
	jQ("#crtclip").parent().find("tr:last").after(htmljoin);
	jQ(data).find("ShareEvent").each(function(){
		var reliedclip=eval(jQ(this).find("reliedclip").text());
		var processstatus=eval(jQ(this).find("processstatus").text());//
		var id=eval(jQ(this).attr("id"));//
		var title=jQ(this).find("title").text();//
		var eventtype=jQ(this).find("eventtype").text();
		var starttime=eval(jQ(this).find("starttime").text());
		var endtime=eval(jQ(this).find("endtime").text());
		var iswholeday=eval(jQ(this).find("iswholeday").text());
		var address=jQ(this).find("address").text();
		var content=jQ(this).find("content").text();
		var pname=jQ(this).find("pname").text();
		var uname=jQ(this).find("uname").text();
		var unameid=jQ(this).find("unameid").text();
		var pnameid=jQ(this).find("pnameid").text();
		
		var unamelogo=jQ(this).find("unamelogo").text();
		var pnamelogo=jQ(this).find("pnamelogo").text();
		
		var isself=jQ(this).find("isself").text();
		var isuserself=eval(jQ(this).find("isuserself").text());
		var isaccept=eval(jQ(this).find("isaccept").text());
		var acceptshareid=jQ(this).find("acceptshareid").text();
		var shareid=jQ(this).find("shareid").text();
		var clipusertype=eval(jQ(this).find("clipusertype").text());
		var reliedclipusertype=eval(jQ(this).find("reliedclipusertype").text());
		jQ("#clipevent-"+id).data("eventid",id);
		jQ("#clipevent-"+id).data("title",title);
		
		jQ("#clipevent-"+id).data("unamelogo",unamelogo);
		jQ("#clipevent-"+id).data("pnamelogo",pnamelogo);
		
		jQ("#clipevent-"+id).data("eventtype",eventtype);
		jQ("#clipevent-"+id).data("starttime",starttime);
		jQ("#clipevent-"+id).data("endtime",endtime);
		jQ("#clipevent-"+id).data("iswholeday",iswholeday);
		jQ("#clipevent-"+id).data("address",address);
		jQ("#clipevent-"+id).data("content",content);
		jQ("#clipevent-"+id).data("processstatus",processstatus);
		jQ("#clipevent-"+id).data("reliedclip",reliedclip);
		jQ("#clipevent-"+id).data("pname",pname);
		jQ("#clipevent-"+id).data("uname",uname);
		
		jQ("#clipevent-"+id).data("pnameid",pnameid);
		jQ("#clipevent-"+id).data("unameid",unameid);
		jQ("#clipevent-"+id).data("isself",isself);
		jQ("#clipevent-"+id).data("isuserself",isuserself);
		jQ("#clipevent-"+id).data("isaccept",isaccept);
		jQ("#clipevent-"+id).data("acceptshareid",acceptshareid);
		jQ("#clipevent-"+id).data("shareid",shareid);
		jQ("#clipevent-"+id).data("clipusertype",clipusertype);
		jQ("#clipevent-"+id).data("reliedclipusertype",reliedclipusertype);
	});
	
	jQ("td.hasevent div.simple span.ocopen").click(function(){
		jQ(this).parent().hide();
		addDetailContent(jQ(this).parent().parent());
		jQ(this).parent().next().fadeIn();
	});
	
	if(length==shareloadlength)
		jQ(window.document).bind("scroll",listenScroll);
}

function sloadAllDetailShareevent(contacttype){
	var type=contacttype;
	jQ.ajax({
		type: "POST",
		url:"shareAjax!getviewShareEventsByDay.action",
		data:{
			contacttype:contacttype
		},
		success:function(data){
			if(type==0)
				organizeviewShareEventsData(data);
			else
				organizeviewfriend_ShareEventsData(data);
		}
	});
}

function organizeviewShareEventsData(data){
	var htmljoin="";
	jQ(data).find("ShareEvent").each(function(i){
		var id=jQ(this).attr("id");
		var uid=jQ(this).find("uid").text();
		var eventtype=jQ(this).find("eventtype").text();
		var title=jQ(this).find("title").text();
		var uname=jQ(this).find("uname").text();
		var starttime=eval(jQ(this).find("starttime").text());
		var userlogo=jQ(this).find("userlogo").text();
		var shareid=jQ(this).find("shareid").text();
		var isuserself=eval(jQ(this).find("isuserself").text());
		if(i>2)
			htmljoin+="<tr linenum='"+i+"' style='display:none;' class='scrollline'>";
		else
			htmljoin+="<tr linenum='"+i+"' class='scrollline'>";
		htmljoin+="<td alleventid='clipevent-"+id+"' class='event' shareid='"+shareid+"' isuserself="+isuserself+">";
		htmljoin+="<div class='event '>";
		htmljoin+="<div class='head' style=\"background:url('"+userlogo+"');\"><a href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+uid+"'></a></div>";
		htmljoin+="<div class='spname'><span class='name'>"+uname+"</span><span class='time' title='开始时间'>"+formateDetailTimeWithhourmin(starttime)+"</span></div>";
		htmljoin+="<div class='sptitle'>"+title+"</div>";
		htmljoin+="</div></td></tr>";
		
	});
	jQ("#smallsharetr").nextAll().remove();
	jQ("#smallsharetr").after(htmljoin);
	jQ("tr.scrollline").click(function(){
		var isuserself=eval(jQ(this).find("td").attr("isuserself"));
		var url="";
		if(isuserself){
			var alleventid=jQ(this).find("td").attr("alleventid");
			var eventid=alleventid.split("-")[1];
			url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?eventid="+eventid;
		}else{
			var shareid=jQ(this).find("td").attr("shareid");
			url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?shareid="+shareid;
		}
		window.location.href=url;
	});
	if(jQ(data).find("ShareEvent").length>3){
		jQ("#smallsharetr").data("max",jQ(data).find("ShareEvent").length);
		jQ("#smallsharetr").data("cur",0);
		jQ("#smallsharetr").data("round",false);
		jQ("tr.scrollline").mouseover(function(){
			clearInterval(scrolllinefun);
		});
		jQ("tr.scrollline").mouseout(function(){
			clearInterval(scrolllinefun);
			scrolllinefun=setInterval(scrollline,5000);
		});
		clearInterval(scrolllinefun);
		scrolllinefun=setInterval(scrollline,5000);
	}
}

var scrolllinefun=null;

function scrollline(){
	
	var max=eval(jQ("#smallsharetr").data("max"));
	var cur=eval(jQ("#smallsharetr").data("cur"));
	var isround=eval(jQ("#smallsharetr").data("round"));
	jQ("tr.scrollline[linenum=" + cur + "]").fadeOut('slow',function(){
		if(!isround){
			if (cur < max - 3) {
				var temp = cur + 3;
				jQ("tr.scrollline[linenum=" + temp + "]").fadeIn('normal');
			}else{
				isround=true;
				jQ("#smallsharetr").data("round",true);
				var temp=cur+3-max;
				var obj=jQ("tr.scrollline[linenum="+temp+"]").clone(true);
				jQ("tr.scrollline[linenum="+temp+"]").remove();
				jQ("#smallsharetable tr:last").after(obj);
				obj.fadeIn('normal');
			}
		}else{
			var temp;
			if (cur < max - 3) 
				temp=cur+3;
			else
			temp=cur+3-max;
			var obj=jQ("tr.scrollline[linenum="+temp+"]").clone(true);
			jQ("tr.scrollline[linenum="+temp+"]").remove();
			jQ("#smallsharetable tr:last").after(obj);
			obj.fadeIn('normal');
		}
		cur++;
		if(cur==max)
			cur=0;
		jQ("#smallsharetr").data("cur",cur);
	});
}
var fscrolllinefun=null;
function organizeviewfriend_ShareEventsData(data){
	var htmljoin="";
	jQ(data).find("ShareEvent").each(function(i){
		var id=jQ(this).attr("id");
		var uid=jQ(this).find("uid").text();
		var eventtype=jQ(this).find("eventtype").text();
		var title=jQ(this).find("title").text();
		var uname=jQ(this).find("uname").text();
		var starttime=eval(jQ(this).find("starttime").text());
		var userlogo=jQ(this).find("userlogo").text();
		var shareid=jQ(this).find("shareid").text();
		var isuserself=eval(jQ(this).find("isuserself").text());
		if(i>2)
			htmljoin+="<tr linenum='"+i+"' style='display:none;' class='fscrollline'>";
		else
			htmljoin+="<tr linenum='"+i+"' class='fscrollline'>";
		htmljoin+="<td alleventid='clipevent-"+id+"' class='event' shareid='"+shareid+"' isuserself="+isuserself+">";
		htmljoin+="<div class='event '>";
		htmljoin+="<div class='head' style=\"background:url('"+userlogo+"')\"><a href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+uid+"'></a></div>";
		htmljoin+="<div class='spname'><span class='name'>"+uname+"</span><span class='time' title='开始时间'>"+formateDetailTimeWithhourmin(starttime)+"</span></div>";
		htmljoin+="<div class='sptitle'>"+title+"</div>";
		htmljoin+="</div></td></tr>";
		
	});
	jQ("#friend_smallsharetr").nextAll().remove();
	jQ("#friend_smallsharetr").after(htmljoin);
	jQ("tr.fscrollline").click(function(){
		var isuserself=eval(jQ(this).find("td").attr("isuserself"));
		var url="";
		if(isuserself){
			var alleventid=jQ(this).find("td").attr("alleventid");
			var eventid=alleventid.split("-")[1];
			url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?eventid="+eventid;
		}else{
			var shareid=jQ(this).find("td").attr("shareid");
			url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?shareid="+shareid;
		}
		window.location.href=url;
	});
	if(jQ(data).find("ShareEvent").length>3){
		jQ("#friend_smallsharetr").data("max",jQ(data).find("ShareEvent").length);
		jQ("#friend_smallsharetr").data("cur",0);
		jQ("#friend_smallsharetr").data("round",false);
		jQ("tr.fscrollline").mouseover(function(){
			clearInterval(fscrolllinefun);
		});
		jQ("tr.fscrollline").mouseout(function(){
			clearInterval(fscrolllinefun);
			fscrolllinefun=setInterval(fscrollline,5000);
		});
		clearInterval(fscrolllinefun);
		fscrolllinefun=setInterval(fscrollline,5000);
	}
}

function fscrollline(){
	
	var max=eval(jQ("#friend_smallsharetr").data("max"));
	var cur=eval(jQ("#friend_smallsharetr").data("cur"));
	var isround=eval(jQ("#friend_smallsharetr").data("round"));
	jQ("tr.fscrollline[linenum=" + cur + "]").fadeOut('slow',function(){
		if(!isround){
			if (cur < max - 3) {
				var temp = cur + 3;
				jQ("tr.fscrollline[linenum=" + temp + "]").fadeIn('normal');
			}else{
				isround=true;
				jQ("#friend_smallsharetr").data("round",true);
				var temp=cur+3-max;
				var obj=jQ("tr.fscrollline[linenum="+temp+"]").clone(true);
				jQ("tr.fscrollline[linenum="+temp+"]").remove();
				jQ("#friend_smallsharetable tr:last").after(obj);
				obj.fadeIn('normal');
			}
		}else{
			var temp;
			if (cur < max - 3) 
				temp=cur+3;
			else
			temp=cur+3-max;
			var obj=jQ("tr.fscrollline[linenum="+temp+"]").clone(true);
			jQ("tr.fscrollline[linenum="+temp+"]").remove();
			jQ("#friend_smallsharetable tr:last").after(obj);
			obj.fadeIn('normal');
		}
		cur++;
		if(cur==max)
			cur=0;
		jQ("#friend_smallsharetr").data("cur",cur);
	});
}


function loadNewShareRecords(){
	var date=eval(jQ("#smallcalendar").data("date"));
	var month=eval(jQ("#smallcalendar").data("month"));
	var year=eval(jQ("#smallcalendar").data("year"));
	jQ.ajax({
		type: "POST",
		url:"shareAjax!countLastShareEventsByDay.action",
		data:{
			year:year,
			month:month,
			date:date,
			contacttype:1
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj.result){
					if(eval(dataObj.count)>0)
						jQ("#updateshares").empty().append("有 "+dataObj.count+" 条分享更新").show();
						jQ("#updateshares").unbind("click").bind("click",function(){
							jQ("#updateshares").empty().hide();
							var date=eval(jQ("#smallcalendar").data("date"));
							var month=eval(jQ("#smallcalendar").data("month"));
							var year=eval(jQ("#smallcalendar").data("year"));
							loadDetailShareevent(year,month,date);
						});
				}
			}
		}
	});
}

function myfunc(obj){
    var tdobj=jQ(obj).parent().parent();
	if(!tdobj.hasClass("hasevent")){
		jQ("#td_box_detail").hide();
	}else{
		var text = tdobj.text();
		var box = tdobj.offset();
		var color = tdobj.find("div").css("background-color");			
		var b_iw = jQ("table.invite_week").offset();
		var w_iw = jQ("table.invite_week").width();
		var bg_position = b_iw.left + w_iw;
		var box_position = box.left + jQ("#td_box_sharedetail").width();
		if(box_position>bg_position){
			jQ("#td_box_sharedetail").css({"top":box.top-35,"left":bg_position - jQ("#td_box_sharedetail").width(),"min-width":tdobj.width()});
			jQ("#td_box_sharedetail div.detailbox").css({"background-color":color});
		}
		else{
			jQ("#td_box_sharedetail").css({"top":box.top-35,"left":box.left,"min-width":tdobj.width()});
			jQ("#td_box_sharedetail div.detailbox").css({"background-color":color});
		}
		addDetailContent(tdobj);
		/*
		jQ("#td_box_detail div.optdiv a.opt").unbind("click").bind("click",function(){
			jQ("#td_box_detail").hide();
			
			jQ(jQid).find("div").css({backgroundPosition: "0px 0px"});
		});*/
		jQ("#td_box_sharedetail").fadeIn();
		
	}
}

function addDetailContent(tdObj){
	
	
	var eventid=jQ(tdObj).data("eventid");
	var title=jQ(tdObj).data("title");
	var eventtype=jQ(tdObj).data("eventtype");
	var starttime=jQ(tdObj).data("starttime");
	var endtime=jQ(tdObj).data("endtime");
	var iswholeday=jQ(tdObj).data("iswholeday");
	var address=jQ(tdObj).data("address");
	var content=jQ(tdObj).data("content");
	var reliedclip=eval(jQ(tdObj).data("reliedclip"));
	var processstatus=eval(jQ(tdObj).data("processstatus"));
	var pname=jQ(tdObj).data("pname");
	var uname=jQ(tdObj).data("uname");
	var isself=eval(jQ(tdObj).data("isself"));
	var pnameid=jQ(tdObj).data("pnameid");
	var unameid=jQ(tdObj).data("unameid");
	var unamelogo=jQ(tdObj).data("unamelogo");
	var pnamelogo=jQ(tdObj).data("pnamelogo");
	var isaccept=eval(jQ(tdObj).data("isaccept"));
	var acceptshareid=jQ(tdObj).data("acceptshareid");
	var shareid=jQ(tdObj).data("shareid");
	var isuserself=eval(jQ(tdObj.data("isuserself")));
	var clipusertype=eval(jQ(tdObj).data("clipusertype"));
	
	var html="";
	
	html+="<ul class=\"detaillist\">";
	html+="<li style='height:auto;'>";
	html+="<span class=\"title\">档期内容：</span>";
	html+="<span class=\"longvalue\" >"+title+"</span>";
	html+="</li>";
	if(reliedclip==0){
		html+="<li style=\"height: 32px;margin-top: 2px;\">";
		html+="	<span style=\"margin-top: 8px;\" class=\"title\">发起人：</span>";
		html+="	<span class=\"detaillogo\" style=\"background: url('"+unamelogo+"');\" onclick=\"window.location.href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+unameid+"'\"></span>";
		html+="	<span class=\"detailname\" onclick=\"window.location.href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+unameid+"'\">"+uname+"</span>";
		if(clipusertype==2)
			html+=" <span class='v_icon' title='档期认证'></span>";
		html+="</li>";
	}else{
		var reliedclipusertype=eval(jQ(tdObj).data("reliedclipusertype"));
		html+="<li style=\"height: 32px;margin-top: 2px;\">";
		html+="<span style=\"margin-top: 8px;\" class=\"title\">转发者：</span>";
		html+="<span class=\"detaillogo\" style=\"background: url('"+unamelogo+"');\" onclick=\"window.location.href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+unameid+"'\"></span>";
		html+="<span class=\"detailname\" onclick=\"window.location.href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+unameid+"'\">"+uname+"</span>";
		if(clipusertype==2)
			html+=" <span class='v_icon' title='档期认证'></span>";
		html+="</li>";
		html+="<li style=\"height: 32px;margin-top: 2px;\">";
		html+="	<span style=\"margin-top: 8px;\" class=\"title\">发起人：</span>";
		html+="	<span class=\"detaillogo\" style=\"background: url('"+pnamelogo+"');\" onclick=\"window.location.href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+pnameid+"'\"></span>";
		html+="	<span class=\"detailname\" onclick=\"window.location.href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+pnameid+"'\">"+pname+"</span>";
		if(reliedclipusertype==2)
			html+=" <span class='v_icon' title='档期认证'></span>";
		html+="</li>";
	}
	html+="<li >";
	html+="<span class=\"title\">活动时间：</span>";
	html+="<span >";
	if(iswholeday){
		html+="<b> 开始于 </b><b>"+formateDetailTimeWithhourmin(starttime)+"</b>";
	}else{
		html+="<b>"+formateDetailTimeWithhourmin(starttime)+"</b><b> 至 </b><b>"+formateDetailTimeWithhourmin(endtime)+"</b>";
	}
	if(processstatus==0){
		html+="<b class=\"edt_ing\">进行中</b>";
	}else if(processstatus==1){
		html+="<b class=\"edt_over\">已结束</b>";
	}else if(processstatus==2){
		html+="<b class=\"edt_stop\">已停止</b>";
	}
	
	html+="</span>";
	html+="</li>";
	if(address!=null&&address.length>0){
		html+="<li style='height:auto;'>";
		html+="<span class=\"title\">活动地点：</span>";
		html+="<span class='longvalue'>"+address+"</span>";
		html+="</li>";
	}
	if(content!=null&&content.length>0){
		html+="<li style='height:auto;'>";
		html+="<span class=\"title\">活动详情：</span>";
		html+="<span class='longvalue'>"+content+"</span>";
		html+="</li>";
	}
	
	html+="</ul>";
	html+=jQ("#calendarzoneout").clone().html();
	html+="<a class='occlose'></a>";
	html+="<div class='btnzone'>";
	html+="<div class='btn'>";
	if(isself){
		html+="<a class=\"forwardshare\"></a>";
		html+="<span class='detail' title='查看详情'></span>";
	}else{
		if(isaccept){
			html+="<a class=\"cancelshare\"></a>";
			html+="<a class=\"forwardshare\"></a>";
		}else
			html+="<a class=\"saveshare\"></a>";
		html+="<span class='detail' title='查看详情'></span>";
	}
	html+="</div>";
	html+="</div>";
	tdObj.children("div.detail").empty();
	tdObj.children("div.detail").append(html).append(jQ("#forwardsharepart").clone());
	if(isaccept){
		tdObj.find("div.detail").append(jQ("#shareoutzone").clone());
		initShareoutBtn(tdObj.find("div.detail"));
	}
	initDetailTimeCalendar(starttime,iswholeday,endtime,tdObj.find("div.detail").find("div.calendarzone"));
	tdObj.find("a.occlose").click(function(){
		jQ(this).parent().hide();
		jQ(this).parent().prev().fadeIn();
	});
	tdObj.find("div.btn>span.detail").unbind("click").bind("click",{tdObj:tdObj.attr("id")},detailEvent);
	tdObj.find("div.btn>a.saveshare").unbind("click").bind("click",{tdObj:tdObj.attr("id")},saveshareEvent);
	tdObj.find("div.btn>a.cancelshare").unbind("click").bind("click",{tdObj:tdObj.attr("id")},cancelshareEvent);
	tdObj.find("div.btn>a.forwardshare").unbind("click").bind("click",{tdObj:tdObj.attr("id")},forwardshareEvent);
}

function detailEvent(event){
	var tdObj=jQ("#"+event.data.tdObj);
	var eventid=eval(tdObj.data("eventid"));
	var isuserself=eval(jQ(tdObj).data("isuserself"));
	var shareid=jQ(tdObj).data("shareid");
	var cliptype=eval(jQ(tdObj).data("cliptype"));
	var date=eval(jQ("#smallcalendar").data("date"));
	var month=eval(jQ("#smallcalendar").data("month"));
	var year=eval(jQ("#smallcalendar").data("year"));
//	jQ.ajax({
//		type: "POST",
//		url:"shareAjax!setClipPlazaDetailQuery.action",
//		data:{
//			year:year,
//			month:month,
//			date:date,
//			contacttype:eval(jQ("#mainshareview").data("contacttype"))
//		},
//		success:function(data){
			if(isuserself){
				window.open(jQ("#ctxVal").val()+"/myclip/clip_detail.html?eventid="+eventid);
			}else{
				window.open(jQ("#ctxVal").val()+"/myclip/clip_detail.html?shareid="+shareid);
			}
//		}
//	});
}

function saveshareEvent(event){
	var tdObj=jQ("#"+event.data.tdObj);
	var eventid=eval(tdObj.data("eventid"));
	var btnobj=jQ(this);
	jQ.ajax({
		type: "POST",
		url:"shareAjax!saveShareEvent.action",
		data:{
			eventid:eval(eventid)
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj.result){
					tdObj.data("isaccept",true);
					tdObj.data("acceptshareid",dataObj.shareid);
					var savedeventid=dataObj.eventid;
					invitingOptReturnBox(btnobj,"保存成功");
					btnobj.removeClass("saveshare").addClass("cancelshare");
					btnobj.unbind("click").bind("click",{tdObj:tdObj.attr("id")},cancelshareEvent);
					btnobj.after("<a class=\"forwardshare\"></a>");
					tdObj.find("div.simple").css("background","#fde9eb");
					tdObj.find("div.detail").append(jQ("#shareoutzone").clone());
					initShareoutBtn(tdObj.find("div.detail"));
					tdObj.find("div.btn>a.forwardshare").unbind("click").bind("click",{tdObj:tdObj.attr("id")},forwardshareEvent);
					jQ("#clipevent-"+savedeventid+" div.simple span.ocopen").click(function(){
						jQ(this).parent().hide();
						addDetailContent(jQ(this).parent().parent());
						jQ(this).parent().next().fadeIn();
					});
				}else{
					alert(dataObj.msg);
					window.location.reload();
				}
			}
		}
	});
	
}

function cancelshareEvent(event){
	var tdObj=jQ("#"+event.data.tdObj);
	
	var acceptshareid=tdObj.data("acceptshareid");
	var btnobj=jQ(this);
	jQ.ajax({
		type: "POST",
		url:"shareAjax!cancelShareEvent.action",
		data:{
			shareid:acceptshareid
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj.result){
					tdObj.data("isaccept",false);
					tdObj.data("acceptshareid","");
					invitingOptReturnBox(btnobj,"取消成功");
					btnobj.removeClass("cancelshare").addClass("saveshare");
					btnobj.unbind("click").bind("click",{tdObj :tdObj.attr("id")},saveshareEvent)
					tdObj.find("div.btn>a.forwardshare").unbind("click").remove();
					tdObj.find("div.simple").css("background","#ffffff");
					tdObj.find("div.detail div.shareoutzone").remove();
				}else{
				}
			}
		}
	});
}

function forwardshareEvent(event){
	var tdObj=event.data.tdObj;
	var btnobj=jQ(this);
	var shareclipzone=btnobj.parent().parent().next();
	shareclipzone.find("div.zonecontent").find("div.share-choose input.sharerd").attr("name",tdObj);
	shareclipzone.find("div.zonecontent").find("div.share-choose input.sharerd:first").attr("checked",true);
	shareclipzone.find("div.contactgrouplist ul").empty().hide();
	var data=jQ("#mainshareview").data("contactgroups");
	var source = jQ( "ContactGroup ", data ).map(function() {
		return {
			label: jQ("groupname", this).text(),
			id: jQ(this).attr("id"),
			membercount: jQ("membercount", this).text(),
			value:jQ("pinyingroupname", this).text()
		};
	}).get();
	shareclipzone.show();
	shareclipzone.find("input.groupnameinput").autocomplete({
		source: source,
		minLength:1,
		select: function( event, ui ) {
			if(ui.item){
				showQuickContactGroup(ui.item.id,ui.item.label,ui.item.membercount,this,null);
			}
		},
		close: function() {
			jQ(this).val("");
		}
	}).data( "autocomplete" )._renderItem = function( ul, item ) {
	return jQ( "<li></li>" )
		.data( "item.autocomplete", item )
		.append( "<a>" + item.label +"</a>" )
		.appendTo( ul );
	};
	
}

function cancelshareclick(obj){
	var choosebtn=jQ(obj).parent();
	var zonecontent=choosebtn.parent();
	zonecontent.parent().hide();
}

function confirmshareclick(obj){
	var contactchoosebtn=jQ(obj).parent();
	var zonecontent=contactchoosebtn.parent();
	var shareclipzone=zonecontent.parent();
	var detail=shareclipzone.parent();
	var liobj=detail.parent();
	var liid=liobj.attr("id");
	
	var sharecbxval=contactchoosebtn.prevAll("div.share-choose").find("input.sharerd:checked").val();
	var contactgrouplist=contactchoosebtn.prevAll("div.share-contactchooseout").find("div.contactgrouplist ul");
	var errzone=contactchoosebtn.prevAll("span.share-errorinfo");
	if(eval(sharecbxval)){
		var templength=jQ("li",contactgrouplist).length;
		if(templength==0){
			errzone.empty();
			errzone.append("请至少选择一个指定群组。");
			errzone.show();
			return;
		}else{
			errzone.empty();
		}
		
	}
	var sharelist='';
	
	if(eval(sharecbxval)){
		var tmphtml="";
		jQ("li",contactgrouplist).each(function(i){
			if(i==0)
				tmphtml=jQ(this).attr("groupid");
			else{
				tmphtml+=","+jQ(this).attr("groupid");
			}
		});
		sharelist=tmphtml;
	}else{
		sharelist="0";
	}
	var eventid=jQ("#"+liid).data("eventid");
	jQ.ajax({
		type: "POST",
		url:"shareAjax!forwardShareEvent.action",
		data:{
			eventid:eval(eventid),
			sharelist:sharelist
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj.result){
					invitingOptReturnBox(obj,"转发成功");
					zonecontent.parent().hide();
				}else{
					
				}
			}
		}
	});
	
}


function invitingOptReturnBox(obj,content){
	var obj_box = jQ(obj);
	var obj_offset = obj_box.offset();
	var msg_box = jQ("#msg_box");
	jQ("#msg_box_content").empty().append(content);
	var _top = obj_offset.top - msg_box.outerHeight()/2;
	var _left = obj_offset.left - msg_box.outerHeight()/2;
	msg_box.css({"top":_top+"px","left":_left+"px"}).show();
	msg_box.find("div.msg_note").animate({top: 20+'px'}, 500,function(){
		setTimeout(function(){
			msg_box.find("div.msg_note").animate({top: 100+'px'},500,function(){msg_box.hide();});
		},2000);
	});
}

function initDetailTimeCalendar(starttime,iswholeday,endtime,calendarzoneobj){
	var startdate=new Date();
	startdate.setTime(starttime);
	var year=startdate.getFullYear();
	var month=startdate.getMonth();
	startdate=new Date(year,month,startdate.getDate());
	var enddate;
	var issameday=false;
	if(!iswholeday){
		enddate=new Date();
		enddate.setTime(endtime);
		enddate=new Date(enddate.getFullYear(),enddate.getMonth(),enddate.getDate());
		issameday=startdate.getTime()==enddate.getTime();
	}else{
		issameday=true;
	}
	detailtimemonth(null,startdate,enddate,issameday,year,month,calendarzoneobj);
	calendarzoneobj.show();
}

function detailtimemonth(event,startdate,enddate,issameday,year,month,calendarzoneobj){
	if(typeof(startdate)=='undefined'){
		startdate=event.data.startdate;
		issameday=event.data.issameday;
		enddate=event.data.enddate;
		month=event.data.month;
		year=event.data.year;
		calendarzoneobj=event.data.calendarzoneobj;
	}
	var firstDateOfMonth=new Date(year,month,1);
	var title=firstDateOfMonth.pattern("yyyy年MM月");
	calendarzoneobj.find("div.title span.title").empty().append(title);
	var week2=firstDateOfMonth.getDay();
	var week1=0;
	var startfromdate=new Date(year,month,1);
	if(week2>week1){
		startfromdate.setDate(firstDateOfMonth.getDate() -week2);
	}
	var endyear,endmonth;
	if(month==11){
		endmonth=0;
		endyear=year+1;
	}else{
		endmonth=month+1;
		endyear=year;
	}
	
	var endDateOfMonth=new Date(endyear,endmonth,1);
	endDateOfMonth.setDate(endDateOfMonth.getDate() -1);
	var week6=6;
	var week5=endDateOfMonth.getDay();
	
	
	var endtodate=new Date(endyear,endmonth,1);
	endtodate.setDate(endtodate.getDate() -1);
	if(week5<week6){
		endtodate.setDate(endDateOfMonth.getDate()+ (week6-week5));
	}
	var index=0;
	
	while(startfromdate.getTime()<=endtodate.getTime()){
		var tdobj=calendarzoneobj.find("td[tid=tddetail"+index+"]");
		tdobj.empty().append(startfromdate.getDate());
		tdobj.removeClass();
		if(startfromdate.getMonth()!=firstDateOfMonth.getMonth(0)){
			if(!issameday){
				if(startfromdate.getTime()>=startdate.getTime()&&startfromdate.getTime()<enddate.getTime()+1){
					tdobj.addClass("selected");
				}else{
					tdobj.addClass("other");
				}
			}
		}else{
			if(issameday){
				if(startfromdate.getTime()==startdate.getTime()){
					tdobj.addClass("selected");
				}
			}else{
				if(startfromdate.getTime()>=startdate.getTime()&&startfromdate.getTime()<enddate.getTime()+1){
					tdobj.addClass("selected");
				}
			}
		}
		index++;
		startfromdate.setDate(startfromdate.getDate() +1);
	}
	if(index==28){
		calendarzoneobj.find("tr[line=4]").hide();
	}else if(index==35){
		calendarzoneobj.find("tr[line=4]").show();
		calendarzoneobj.find("tr[line=5]").hide();
	}else{
		calendarzoneobj.find("tr[line=4]").show();
		calendarzoneobj.find("tr[line=5]").show();
	}
	
	if(issameday){
		calendarzoneobj.find("div.title a").addClass("none");
	}else{
		if(startdate.getTime()<firstDateOfMonth.getTime()){
			var temp1=new Date(firstDateOfMonth.getFullYear(),firstDateOfMonth.getMonth(),firstDateOfMonth.getDate());
			temp1.setMonth(temp1.getMonth()-1);
			var tempyear=temp1.getFullYear();
			var tempmonth=temp1.getMonth();
			calendarzoneobj.find("div.title a.prev").removeClass("none").unbind("click")
				.bind("click",{startdate:startdate,enddate:enddate,issameday:issameday,year:tempyear,month:tempmonth,calendarzoneobj:calendarzoneobj},detailtimemonth);
		}else{
			calendarzoneobj.find("div.title a.prev").addClass("none").unbind("click");
		}
		var tempdate=new Date(endDateOfMonth.getFullYear(),endDateOfMonth.getMonth(),endDateOfMonth.getDate());
		tempdate.setDate(tempdate.getDate()+ 1);
		if(enddate.getTime()>tempdate.getTime()){
			var tempyear=tempdate.getFullYear();
			var tempmonth=tempdate.getMonth();
			calendarzoneobj.find("div.title a.next").removeClass("none").unbind("click")
			.bind("click",{startdate:startdate,enddate:enddate,issameday:issameday,year:tempyear,month:tempmonth,calendarzoneobj:calendarzoneobj},detailtimemonth);
		}else{
			calendarzoneobj.find("div.title a.next").addClass("none").unbind("click");
		}
	}
}

function initShareoutBtn(detailobj){
	var liobj=detailobj.parent();
	detailobj.find("a.renrenlogo").unbind("click").bind("click",function(){
		var isuserself=eval(jQ(liobj).data("isuserself"));
		var title=jQ(liobj).data("title");
		var starttime=jQ(liobj).data("starttime");
		var shareid;
		if(isuserself){
			shareid=jQ(liobj).data("shareid");
		}else{
			shareid=jQ(liobj).data("acceptshareid");
		}
		var day=new Date();
		day.setTime(starttime);
		var startstr=day.pattern("yyyy年MM月dd日");
		
		
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?shareid="+shareid;
		window.open(
		'http://www.connect.renren.com/share/sharer?url='+url
		+'&title=档期分享：'+startstr+'  '+title+'    '+'更多详情请点击',
		'_blank',
		'height=290,width=510,top=200,left=430,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no'); 
	});
	detailobj.find("a.kaixin001logo").unbind("click").bind("click",function(){
		var isuserself=eval(jQ(liobj).data("isuserself"));
		var title=jQ(liobj).data("title");
		var starttime=jQ(liobj).data("starttime");
		var shareid;
		if(isuserself){
			shareid=jQ(liobj).data("shareid");
		}else{
			shareid=jQ(liobj).data("acceptshareid");
		}
		var day=new Date();
		day.setTime(starttime);
		var startstr=day.pattern("yyyy年MM月dd日");
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?shareid="+shareid;
		window.open(
		'http://www.kaixin001.com/repaste/share.php?rurl='+url
		+'&rtitle=档期分享'
		+'&rcontent='+startstr+'  '+title+'    '+'更多详情请点击',
		'_blank',
		'height=500,width=700,top=200,left=410,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
	});
	detailobj.find("a.sinalogo").unbind("click").bind("click",function(){
		var isuserself=eval(jQ(liobj).data("isuserself"));
		var title=jQ(liobj).data("title");
		var starttime=jQ(liobj).data("starttime");
		var shareid;
		if(isuserself){
			shareid=jQ(liobj).data("shareid");
		}else{
			shareid=jQ(liobj).data("acceptshareid");
		}
		var day=new Date();
		day.setTime(starttime);
		var startstr=day.pattern("yyyy年MM月dd日");
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?shareid="+shareid;
		var param = {
		    url:url,
		    type:'3',
		    title:'档期分享：'+startstr+'  '+title+'    '+'更多详情请点击',
		    pic:'',
		    ralateUid:'2618696840',
			language:'zh_cn',
		    rnd:new Date().valueOf()
		  }
		var temp = [];
		for( var p in param ){
			temp.push(p + '=' + encodeURIComponent( param[p] || '' ) )
		}
		
		window.open(
				'http://service.weibo.com/share/share.php?' + temp.join('&') ,
				'_blank',
		'height=520,width=607,top=150,left=410,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
	});
	detailobj.find("a.doubanlogo").unbind("click").bind("click",function(){
		var isuserself=eval(jQ(liobj).data("isuserself"));
		var title=jQ(liobj).data("title");
		var starttime=jQ(liobj).data("starttime");
		var shareid;
		if(isuserself){
			shareid=jQ(liobj).data("shareid");
		}else{
			shareid=jQ(liobj).data("acceptshareid");
		}
		var day=new Date();
		day.setTime(starttime);
		var startstr=day.pattern("yyyy年MM月dd日");
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/myclip/clip_detail.html?shareid="+shareid;
		window.open(
		'http://www.douban.com/recommend/?url='+url
		+'&title=档期分享'+
		+'&comment='+startstr+'  '+title+'    '+'更多详情请点击',
		'_blank',
		'height=370,width=505,top=300,left=450,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
	});
}


function saveshare(){
	var cansave=eval(jQ("#td_box_sharedetail").data("savebtn"));
	if(cansave){
		var eventid=jQ("#td_box_sharedetail").data("eventid");
		jQ.ajax({
			type: "POST",
			url:"shareAjax!saveShareEvent.action",
			data:{
				eventid:eval(eventid)
			},
			success:function(data){
				if(data!=null){
					var dataObj=eval("("+data+")");//转换为json对象
					if(dataObj.result){
						alert("保存成功");
						jQ("#td_box_sharedetail").data("savebtn",false);
						jQ("#td_box_sharedetail").data("forwardbtn",true);
						jQ("#savebtn").removeClass().addClass("disablesaveshare");
						jQ("#forwardbtn").removeClass().addClass("forwardshare");
						jQ("#clipevent-"+eventid).find("div.event").addClass("acceptevent");
						var color = jQ("#clipevent-"+eventid).find("div.event").css("background-color");
						jQ("#td_box_sharedetail div.detailbox").css({"background-color":color});
						jQ("#clipevent-"+eventid).data("hasaccept",1);
						
					}else{
						alert(dataObj.msg);
						window.location.reload();
					}
				}
			}
		});
	}
}

function forwardshare(obj){
	var canforward=eval(jQ("#td_box_sharedetail").data("forwardbtn"));
	if(canforward)
		jQ("#forwardsharepart").toggle();
}

function confirmshare(){
	var canforward=eval(jQ("#td_box_sharedetail").data("forwardbtn"));
	if(canforward){
		var sharecbxval=jQ('input[name=shareraido]:checked').val();
		if(eval(sharecbxval)){
			var templength=jQ("li",jQ("#contactgrouplist")).length;
			errzone=jQ("#share-errorinfo");
			if(templength==0){
				errzone.empty();
				errzone.append("请至少选择一个指定群组。");
				errzone.show();
				return;
			}else{
				errzone.empty();
			}
			
		}
		var sharelist='';
		
		var sharecbxval=jQ('input[name=shareraido]:checked').val();
		if(eval(sharecbxval)){
			var tmphtml="";
			jQ("#contactgrouplist li").each(function(i){
				if(i==0)
					tmphtml=jQ(this).attr("groupid");
				else{
					tmphtml+=","+jQ(this).attr("groupid");
				}
			});
			sharelist=tmphtml;
		}else{
			sharelist="0";
		}
		var eventid=jQ("#td_box_sharedetail").data("eventid");
		jQ.ajax({
			type: "POST",
			url:"shareAjax!forwardShareEvent.action",
			data:{
				eventid:eval(eventid),
				sharelist:sharelist
			},
			success:function(data){
				if(data!=null){
					var dataObj=eval("("+data+")");//转换为json对象
					if(dataObj.result){
						alert("转发成功");
						var shareid=dataObj.shareid;
						jQ("#shareoutzone").show();
						jQ("#shareoutzone").data("acceptshareid",shareid);
						initShareOutofSite();
						jQ("#contactgrouplist").empty().hide();
						jQ("#forwardsharepart").toggle();
//						jQ("#td_box_sharedetail").data("savebtn",false);
//						jQ("#td_box_sharedetail").data("forwardbtn",true);
//						jQ("#savebtn").removeClass().addClass("disablesaveshare");
//						jQ("#forwardbtn").removeClass().addClass("forwardshare");
//						jQ("#clipevent-"+eventid).find("div.event").addClass("acceptevent");
//						var color = jQ("#clipevent-"+eventid).find("div.event").css("background-color");
//						jQ("#td_box_sharedetail div.detailbox").css({"background-color":color});
					}else{
//						alert(dataObj.msg);
//						window.location.reload();
					}
				}
			}
		});
	}
}
function cancelshare(){
	var canforward=eval(jQ("#td_box_sharedetail").data("forwardbtn"));
	if(canforward)
		jQ("#forwardsharepart").toggle();
}

function changeContactType(type){
	if(type!=0&&type!=1){
		return;
	}else{
		jQ("#mainshareview").data("contacttype",type);
		if(type==0){
			jQ("#shareallplace").fadeOut('normal',fadeOutCallBack);
			jQ("#sharetitle").empty().append("分享广场").removeClass().addClass("shareall");
		}else{
			jQ("#sharefriendplace").fadeOut('normal',fadeOutCallBack);
			jQ("#sharetitle").empty().append("好友分享").removeClass().addClass("sharefriend");
		}
		
		
	}
}

function fadeOutCallBack(){
	var type=1-eval(jQ("#mainshareview").data("contacttype"));
	getShareEventsByMonth(0,0,0,eval(jQ("#mainshareview").data("contacttype")));
	if(type==1){
		jQ("#sharefriendplace").fadeIn();
	}else{
		jQ("#shareallplace").fadeIn();
	}
	sloadAllDetailShareevent(type);
}

function currentMonthClick(){
	jQ("#loadingui").show();
	var tY=eval(jQ("#divtodaydetailtime").data("year"));
	var tM=eval(jQ("#divtodaydetailtime").data("month"));
	jQ("#mouth_fun_view_year option[value='"+tY+"']").attr("selected",true);
	jQ("#mouth_fun_view_month option[value='"+tM+"']").attr("selected",true);
	var contacttype=eval(jQ("#mainshareview").data("contacttype"));
	getShareEventsByMonth(tY, tM,1,contacttype);
}
function changeMonthView(){
	jQ("#loadingui").show();
	var year=eval(jQ("#mouth_fun_view_year").val());
	var month=eval(jQ("#mouth_fun_view_month").val());
	var contacttype=eval(jQ("#mainshareview").data("contacttype"));
	getShareEventsByMonth(year, month,1,contacttype);
	
}

function prevYearClick(){
	var year=eval(jQ("#mouth_fun_view_year").val());
	year=year-1;
	var month=eval(jQ("#mouth_fun_view_month").val());
	jQ("#mouth_fun_view_year option[value='"+(year)+"']").attr("selected",true);
	jQ("#mouth_fun_view_year").trigger("change");
}
function prevMonthClick(){
	var year=eval(jQ("#mouth_fun_view_year").val());
	var month=eval(jQ("#mouth_fun_view_month").val());
	if(month==0){
		month=11;
		year=year-1;
	}else{
		month=month-1;
	}
	jQ("#mouth_fun_view_year option[value='"+year+"']").attr("selected",true);
	jQ("#mouth_fun_view_month option[value='"+month+"']").attr("selected",true);
	jQ("#mouth_fun_view_year").trigger("change");
}
function nextMonthClick(){
	var year=eval(jQ("#mouth_fun_view_year").val());
	var month=eval(jQ("#mouth_fun_view_month").val());
	if(month==11){
		month=0;
		year=year+1;
	}else{
		month=month+1;
	}
	jQ("#mouth_fun_view_year option[value='"+year+"']").attr("selected",true);
	jQ("#mouth_fun_view_month option[value='"+month+"']").attr("selected",true);
	jQ("#mouth_fun_view_year").trigger("change");
}
function nextYearClick(){
	var year=eval(jQ("#mouth_fun_view_year").val());
	year=year+1;
	var month=eval(jQ("#mouth_fun_view_month").val());
	jQ("#mouth_fun_view_year option[value='"+(year)+"']").attr("selected",true);
	jQ("#mouth_fun_view_year").trigger("change");
}

function formateDetailTime(daytime){
	var day=new Date();
	day.setTime(daytime);
	return day.pattern("MM月dd日");
}

function formateSmallDetailTime(day){
	return day.pattern("MMdd");
}

function formateTitleDetailTime(day){
	return day.pattern("yyyy.MM.dd");
}

function formateDetailTimeWithhourmin(daytime){
	var day=new Date();
	day.setTime(daytime);
	return day.pattern("yyyy-MM-dd HH:mm");
}

function getWordsLength(words,fontsize){
	jQ("#fontwidthtools").css("font-size",fontsize+"px");
	jQ("#fontwidthtools").empty().append(words);
	return jQ("#fontwidthtools")[0].offsetWidth;
}